/**
 * 同步：时间戳加while循环
 *
 * @param {*} delay  毫秒
 */
function sleep(delay) {
  let now = Date.now();

  while (Date.now() - now <= delay) {}
}

/**
 * 异步方法：promise+setTimeout
 * @param {*} delay
 * @returns
 */
function sleep2(delay) {
  return new Promise((resolve, reject) => {
    setTimeout(resolve, delay);
  });
}

// egg
console.log("[ 1 ] >", 1);
sleep(1000);
console.log("[ 2 ] >", 2);
sleep2(1000).then(() => {
  console.log("[ 3 ] >", 3);
});
